<?php

require_once("../conn.php");

$total = 20;
if (isset($_GET['module'])) {
    $module = $_GET['module'];

    $codes = $_POST['code'];
    $names = $_POST['name'];
    $nums = $_POST['num'];

    $db = new DBC();
    if ($module == "suggest") {
        $sql = "DELETE FROM t_market_suggest";
        if ($db->execute($sql)) {
            for ($i = 0; $i < $total; $i++) {
                if ($codes[$i] != "" && $names[$i] != "") {
                    $sql = "INSERT INTO t_market_suggest(code,name,num) VALUES('" . $codes[$i] . "','" . $names[$i] . "'," . $nums[$i] . ")";
                    $db->execute($sql);
                }
            }
        }
        $transfer = "marketSuggest.php?method=modify&menu=suggest";
    } else if ($module == "download") {
        $downs = $_POST['downloadTimes'];
        $sql = "DELETE FROM t_market_downloadTimes";
        if ($db->execute($sql)) {
            for ($i = 0; $i < $total; $i++) {
                if ($codes[$i] != "" && $names[$i] != "") {
                    $sql = "INSERT INTO t_market_downloadTimes(code,name,downloadTimes,num) VALUES('" . $codes[$i] . "','" . $names[$i] . "'," . $downs[$i] . "," . $nums[$i] . ")";
                    $db->execute($sql);
                }
            }
        }
        $transfer = "marketDownload.php?method=modify&menu=download";
    } else if ($module == "uploadtime") {
        $uploads = $_POST['uploadTime'];        
        $sql = "DELETE FROM t_market_uploadtime";        
        if ($db->execute($sql)) {
            for ($i = 0; $i < $total; $i++) {
                if ($codes[$i] != "" && $names[$i] != "") {
                    $sql = "INSERT INTO t_market_uploadtime(code,name,uploadTime,num) VALUES('" . $codes[$i] . "','" . $names[$i] . "','" . $uploads[$i] . "'," . $nums[$i] . ")";
                    
                    $db->execute($sql);
                }
            }
        }
        $transfer = "marketUpload.php?method=modify&menu=uploadtime";
    }    
    echo "<script language='javascript'>location='" . $transfer . "';</script>";
} else {
    echo "<script language='javascript'>history.back();</script>";
}
?>
